import speech_recognition
import pyttsx3
import cv2

recognizer = speech_recognition.Recognizer()
engine = pyttsx3.init()
while True:
    try:
        with speech_recognition.Microphone() as mic:
            #调整环境噪声
            recognizer.adjust_for_ambient_noise(mic,duration=0.2)
            audio = recognizer.listen(mic)

            text = recognizer.recognize_google(audio)
            text = text.lower()
            print(f'{text}')
    except speech_recognition.UnknownValueError():
        engine.say("wrong")
        engine.runAndWait()
        engine.stop()